package com.hmall.Item.web;

import com.hmall.Item.pojo.RequestParams;
import com.hmall.Item.service.SearchService;
import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;

import org.elasticsearch.client.RestHighLevelClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;


import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;
    @Autowired
    private RestHighLevelClient client;

    //搜索框自动补全
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix) throws IOException {
        return searchService.getSuggestions(prefix);
    }

    //聚合
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.filters(params);
    }

    //查询
    @PostMapping("/list")
    public PageDTO<Item> search(@RequestBody RequestParams params){
        return searchService.search(params);
    }
}

